package com.web.music.impl;

import com.web.music.model.SecuredEntity;
import com.web.music.model.User;

public class SecurityHelper {

	private static boolean isAdministrator(User user) {
		return "Y".equals(user.getIsAdmin());
	}

	public static boolean isUpdateGranted(SecuredEntity entity, User currentUser) {
		if (currentUser == null) {
			//Anonymous user
			return false;
		} else {
			if (isAdministrator(currentUser)) {
				return true;
			}
			User createdBy = entity.getCreatedBy();
			if (createdBy == null) {
				return false;
			}
			return createdBy.getId().equals(currentUser.getId());
		}
	}
	
}